//var timeLength=60;
var mPhone=""+GetQueryString("mPhone");
var processing = false;
var flag=false;
$(function(){
	//startTimer(timeLength);
	$("#mPhone").text(mPhone.substring(0, 3) + "****" + mPhone.substring(7, 11))
	$("#confirmCode").click(function(){
		var data = $("form").serialize();
		if(flag){
			console.log(flag)
			$.ajax({
				type:"post",
				url:rootPath+"/register/validateCode",
				data:data,
				success:function(data){
					if(data.resultSuccess){
						window.location.href=rootPath+"/register/reset_psw?mPhone="+data.data;
					}else{
						$("#msg").text(data.resultDesc);
					}
					
				}
			})
		}
		
	})
})
//验证身份
$("#daojishi").click(function(){
		//发送验证码
		$.ajax({
			type:"post",
			url:rootPath+"/captcha/getCaptcha",
			data:{'mPhone':mPhone,'mStyle':2},
			//dataType:"json",
			success:function(data){
				if(data.resultSuccess){
					flag=true;
				}else{
					$("#msg").text(data.resultDesc);
				}
			}
		})
		var i = 60;
        if (processing) return ;
        time($(".reset .main .verify form span"));
		if(i!=0) {
			return false;
		}else{
			return true;
		};
		function time(o) {
			  if (i == 0) {
			 	 o.removeAttr("disabled");
			     processing = false;   
			     o.html("获取验证码"); 
			     wait = 30;
			  } else {
			     o.attr("disabled",true); 
			     o.html("重新发送(" + i + ")");
			     i--;
			     processing = true;
			     setTimeout(function(){ 
			       time(o)
			     },1000)               
			  }
			}
		
});

function GetQueryString(name) {  
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");  
    var r = window.location.search.substr(1).match(reg);  //获取url中"?"符后的字符串并正则匹配
    var context = "";  
    if (r != null)  
         context = r[2];  
    reg = null;  
    r = null;  
    return context == null || context == "" || context == "undefined" ? "" : context;  
}